<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{padding:10px;margin:10px;border:solid 1px black;}
    </style>
</head>
<body>
    <div class="app">
        <h1>这是 - {{title}}</h1>
        <p>这是父组件的数：{{data.name}}</p>

        <Child1 :tit="title" :msg="data"></Child1>
    </div>
</body>
<template id="child1Temp">
    <div>
        <h3>这是 - {{title}}</h3>
        <p>父组件传来的了：{{str}} - <input type="text" v-model="str"> - {{typeof msg}}</p>
        <p>父组件传来的了：{{sayHello}} - <input type="text" v-model="sayHello"> - {{typeof sayHello}}</p>
    </div>
</template>
<script src="../vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data(){
            return {
                title: "根组件",
                data:{
                    name:"张三"
                }
            }
        },
        components:{
            Child1: {
                data(){
                    return {
                        title:"子组件1",
                        str:"",
                        a:"hello "
                    }
                },
                template:"#child1Temp",
                props: ["tit", "msg"],
                mounted() {
                    // 将父组件传入的数据，保存到当前实例的某个响应式数据
                    this.str = this.tit;
                    this.a = "hello " + this.msg.name;
                },
                computed:{
                    // 根据某个响应式属性，定义计算属性
                    sayHello:{
                        get(){
                            return this.a;
                        },
                        set(v){
                            this.a = v;
                        }
                    }
                }
            }
        }
    })

    app.mount(".app");

</script>
</html>